<?php

class Jf_View_Helper_AdminURL extends Jf_View_Helper_Abstract {

    public function adminURL ($action, $params = null) {
        $dispatcher = Jf_Controller_Dispatcher::getInstance ();
        $module = $dispatcher -> getRequest () -> getModuleName ();
        if (strpos ($action, '/')) {
            $temp = explode ('/', $action);
            $controller = array_shift ($temp);
            $action = array_shift ($temp);
        } else {
            $controller = $dispatcher -> getRequest () -> getControllerName ();
        }
        if (is_array ($params)) {
            $params = '?' . http_build_query ($params);
        }
        $url = $dispatcher -> getRequest () -> getScheme () . '://' . $dispatcher -> getRequest () -> getHttpHost () . strtolower ('/' . $module . '/' . $controller . '/' . $action . $params);
        return $url;
    }

}
